using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Common;

namespace SExperiment.ExperimentResult
{
    [Serializable]
    public class TargetResult : BaseResult
    {
        private Curve _RawCurve = new Curve();

        [NonSerialized]
        private Curve _AMPCurve = new Curve();

        [NonSerialized]
        private double _CtValue = double.NaN;

        [NonSerialized]
        private double _CtMean = double.NaN;

        [NonSerialized]
        private double _CtSD = double.NaN;

        [NonSerialized]
        private double _CtCV = double.NaN;

        [NonSerialized]
        private double _CnValue = double.NaN;

        [NonSerialized]
        private double _CnMean = double.NaN;

        [NonSerialized]
        private double _CnSD = double.NaN;

        [NonSerialized]
        private double _CnCV = double.NaN;

        [NonSerialized]
        private double _RnValue = double.NaN;

        public Curve RawCurve
        {
            get
            {
                return _RawCurve;
            }
            set
            {
                if (_RawCurve != value)
                {
                    _RawCurve = value;
                    OnPropertyChanged("RawCurve");
                }
            }
        }

        public Curve AMPCurve
        {
            get
            {
                return _AMPCurve;
            }
            set
            {
                if (_AMPCurve != value)
                {
                    _AMPCurve = value;
                    OnPropertyChanged("AMPCurve");
                }
            }
        }

        public double CtValue
        {
            get
            {
                return _CtValue;
            }
            set
            {
                if (_CtValue != value)
                {
                    _CtValue = value;
                    OnPropertyChanged("CtValue");
                }
            }
        }

        public double CtMean
        {
            get
            {
                return _CtMean;
            }
            set
            {
                if (_CtMean != value)
                {
                    _CtMean = value;
                    OnPropertyChanged("CtMean");
                }
            }
        }

        public double CtSD
        {
            get
            {
                return _CtSD;
            }
            set
            {
                if (_CtSD != value)
                {
                    _CtSD = value;
                    OnPropertyChanged("CtSD");
                }
            }
        }

        public double CtCV
        {
            get
            {
                return _CtCV;
            }
            set
            {
                if (_CtCV != value)
                {
                    _CtCV = value;
                    OnPropertyChanged("CtCV");
                }
            }
        }

        public double CnValue
        {
            get
            {
                return _CnValue;
            }
            set
            {
                if (_CnValue != value)
                {
                    _CnValue = value;
                    OnPropertyChanged("CnValue");
                }
            }
        }

        public double CnMean
        {
            get
            {
                return _CnMean;
            }
            set
            {
                if (_CnMean != value)
                {
                    _CnMean = value;
                    OnPropertyChanged("CnMean");
                }
            }
        }

        public double CnSD
        {
            get
            {
                return _CnSD;
            }
            set
            {
                if (_CnSD != value)
                {
                    _CnSD = value;
                    OnPropertyChanged("CnSD");
                }
            }
        }

        public double CnCV
        {
            get
            {
                return _CnCV;
            }
            set
            {
                if (_CnCV != value)
                {
                    _CnCV = value;
                    OnPropertyChanged("CnCV");
                }
            }
        }

        public double RnValue
        {
            get
            {
                return _RnValue;
            }
            set
            {
                if (_RnValue != value)
                {
                    _RnValue = value;
                    OnPropertyChanged("RnValue");
                }
            }
        }

        [OnDeserialized]
        private void OnDeserialized(StreamingContext context)
        {
            if (_RawCurve == null)
            {
                _RawCurve = new Curve();
            }
            _AMPCurve = new Curve();
        }

        public override void GetDatesAndKeys(List<PropertyKey> keys, List<byte[]> datas)
        {
            base.GetDatesAndKeys(keys, datas);
            keys.Add(PropertyKey.Key_CtValue);
            datas.Add(BytesConverter.GetBytes(CtValue));
            keys.Add(PropertyKey.Key_CtMean);
            datas.Add(BytesConverter.GetBytes(CtMean));
            keys.Add(PropertyKey.Key_CtSD);
            datas.Add(BytesConverter.GetBytes(CtSD));
            keys.Add(PropertyKey.Key_CtCV);
            datas.Add(BytesConverter.GetBytes(CtCV));
            keys.Add(PropertyKey.Key_CnValue);
            datas.Add(BytesConverter.GetBytes(CnValue));
            keys.Add(PropertyKey.Key_CnMean);
            datas.Add(BytesConverter.GetBytes(CnMean));
            keys.Add(PropertyKey.Key_CnSD);
            datas.Add(BytesConverter.GetBytes(CnSD));
            keys.Add(PropertyKey.Key_CnCV);
            datas.Add(BytesConverter.GetBytes(CnCV));
            keys.Add(PropertyKey.Key_RnValue);
            datas.Add(BytesConverter.GetBytes(RnValue));
        }

        public override void SetDatesAndKeys(List<PropertyKey> keys, List<byte[]> datas)
        {
            base.SetDatesAndKeys(keys, datas);
            for (int i = 0; i < keys.Count; i++)
            {
                switch (keys[i])
                {
                    case PropertyKey.Key_CtValue:
                        CtValue = BytesConverter.BytesToDouble(datas[i]);
                        break;
                    case PropertyKey.Key_CtMean:
                        CtMean = BytesConverter.BytesToDouble(datas[i]);
                        break;
                    case PropertyKey.Key_CtSD:
                        CtSD = BytesConverter.BytesToDouble(datas[i]);
                        break;
                    case PropertyKey.Key_CtCV:
                        CtCV = BytesConverter.BytesToDouble(datas[i]);
                        break;
                    case PropertyKey.Key_CnValue:
                        CnValue = BytesConverter.BytesToDouble(datas[i]);
                        break;
                    case PropertyKey.Key_CnMean:
                        CnMean = BytesConverter.BytesToDouble(datas[i]);
                        break;
                    case PropertyKey.Key_CnSD:
                        CnSD = BytesConverter.BytesToDouble(datas[i]);
                        break;
                    case PropertyKey.Key_CnCV:
                        CnCV = BytesConverter.BytesToDouble(datas[i]);
                        break;
                    case PropertyKey.Key_RnValue:
                        RnValue = BytesConverter.BytesToDouble(datas[i]);
                        break;
                }
            }
        }
    }
}
